package com.Inter.T01;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class O01 {
    public static void main(String[] args) throws IOException {
        // 1. 创建对象
        DatagramSocket ds = new DatagramSocket();
        Scanner sc = new Scanner(System.in);
        
        // 设置发送地址和端口
        InetAddress byName = InetAddress.getByName("127.0.0.1");
        int port = 10011;
        while (true) {
            System.out.println("请输入发送的内容");
            String s = sc.nextLine();
            System.out.println(s);
            byte[] bytes = s.getBytes();
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, byName, port);
            // 发送数据
            ds.send(dp);
            if("886".equals(s)){
                break;
            }
        }
        
        // 释放资源
        ds.close();
    }
}
